package org.neframework.webtest.service;

import java.util.List;
import java.util.Map;

import org.neframework.webtest.model.t_fk_user;

import com.tmsps.neframework.core.common.page.Page;
import com.tmsps.neframework.core.utils.MD5;
import com.tmsps.neframework.jpa.base.BaseService;
import com.tmsps.neframework.jpa.sql.param.NeParamList;
import com.tmsps.neframework.mvc.annotation.task.Task;

public class UserService extends BaseService {

	public t_fk_user selectUserByEmailAndPwd(String uname, String pwd) {
		// TODO 账号密码查询
		String sql = "select * from t_fk_user t where t.status=0 and t.uname=? and t.pwd=?";
		t_fk_user user = (t_fk_user) oc.findObj(sql, new String[] { uname, pwd }, t_fk_user.class);
		return user;
	}

	public List<Map<String, Object>> selectAdminList(String srh_uname, Map<String, String> sort_params, Page page) {
		// TODO 查询管理员列表
		String sql = "select * from t_fk_user t where t.status=0 and (t.uname like ?) and t.type='管理员' ";
		NeParamList params = NeParamList.makeParams();
		params.addLike(srh_uname);

		List<Map<String, Object>> list = jcn.queryForList(sql, params, sort_params, page);
		return list;
	}

	@Task(code = "080050", tip = "用户人数(@cnt)")
	public Long selectUserList() {
		// TODO 查询管理员列表
		String sql = "select count(*) cnt from t_fk_user t where t.status=0 and t.type='普通用户' ";

		Long cnt = (Long) jc.queryForMap(sql).get("cnt");

		return cnt;
	}

	public List<Map<String, Object>> selectUserList(String srh_uname, Map<String, String> sort_params, Page page) {
		// TODO 查询管理员列表
		String sql = "select * from t_fk_user t where t.status=0 and (t.uname like ?) and t.type='普通用户' ";
		NeParamList params = NeParamList.makeParams();
		params.addLike(srh_uname);

		System.err.println("sort_params-->" + sort_params);

		List<Map<String, Object>> list = jcn.queryForList(sql, params, sort_params, page);
		return list;
	}

	public static void main(String[] args) {
		UserService s = new UserService();
		System.err.println(MD5.md5("123456"));
		System.err.println(s.selectUserByEmailAndPwd("admin", MD5.md5("123456")));

	}

}
